package com.qc.controller;

import com.qc.dto.Result;
import com.qc.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.qc.enity.Message;
import java.util.List;

@RestController
@RequestMapping("message")
@CrossOrigin
public class MessageController {
    @Autowired
    private IMessageService messageService;

    // 保存消息
    @PostMapping("/save")
    public Result saveMessage(@RequestBody Message message) {
        try {
            int i = messageService.saveMessage(message);
            return Result.successResult(i);
        } catch (Exception e) {
            return Result.error("500", e.getMessage());
        }
    }

    // 获取所有消息
    @GetMapping("/all")
    public Result getAllMessages(@RequestParam("userid") Integer userid) {
        try {
            List<Message> messageList = messageService.messageList(userid);
            return Result.successResult(messageList);
        } catch (Exception e) {
            return Result.error("500", e.getMessage());
        }
    }
}
